package main

import "fmt"

//条件判断 循环遍历
func main() {
	/*** IF 写法  ***/
	a := 60
	if a >= 60 {
		fmt.Println("a is ok")
	} else {
		fmt.Println("a is bad")
	}
	//支持一个初始化语句，初始化语句和条件判断以分号分隔,不能用(  )
	if b := 60; b >= 60 {
		fmt.Println("b is ok")
	} else {
		fmt.Println("b is bad")
	}

	if c := 80; c < 60 {
		fmt.Println("c < 60")
	} else if c == 60 {
		fmt.Println("c == 60")
	} else if c > 60 {
		fmt.Println("c > 60")
	}

	/**** switch ****/
	var num byte
	fmt.Printf("请输入数字：")
	fmt.Scan(&num)
	//支持1个初始化句语
	switch num {
	case 1: //默认包含break
		fmt.Println("this is 1")
		fallthrough //fallthrough 不需要break,传递下一个无条件执行
	case 2:
		fmt.Println("this is 2")
		fallthrough
	case 3, 4, 5:
		fmt.Println("this is 3,4,5")
		fallthrough
	default:
		fmt.Println("other number")
	}

	k := 10
	switch {
	case k > 10:
		fmt.Println("k > 10")
	case k == 10:
		fmt.Println("k == 10")
	case k < 10:
		fmt.Println("k < 10")
	default:
		fmt.Println("k is default")
	}

	/*** for ***/
	for i := 1; i < 100; i++ {
		a = a + i
	}
	fmt.Println("a=", a)

	/** range **/
	m := "abc"
	for i, data := range m {
		fmt.Printf("m[%d]=%c\n", i, data)
	}
}
